/**
 * 类型定义文件
 * 定义前端应用中使用的通用类型
 */

// 通用响应类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
  success?: boolean
}

export interface PaginationParams {
  page: number
  page_size: number
  ordering?: string
  search?: string
}

export interface PaginatedResponse<T> {
  count: number
  next?: string
  previous?: string
  results: T[]
}

// 用户相关类型
export interface User {
  id: number
  username: string
  real_name: string
  email: string
  phone?: string
  student_id?: string
  avatar?: string
  role: 'student' | 'teacher' | 'admin'
  is_active: boolean
  created_at: string
  updated_at: string
}

export interface UserProfile {
  id: number
  user: number
  bio?: string
  education?: string
  work_experience?: string
  skills?: string[]
  avatar?: string
  created_at: string
  updated_at: string
}

// 认证相关类型
export interface LoginRequest {
  username: string
  password: string
}

export interface RegisterRequest {
  username: string
  password: string
  real_name: string
  email: string
  role: 'student' | 'teacher'
  student_id?: string
  phone?: string
}

export interface LoginResponse {
  access_token: string
  refresh_token: string
  user: User
  token_type: string
  expires_in: number
}

export interface RefreshTokenRequest {
  refresh_token: string
}

// 题库相关类型
export interface QuestionBank {
  id: number
  name: string
  description: string
  creator: User
  is_public: boolean
  question_count: number
  created_at: string
  updated_at: string
}

export interface Question {
  id: number
  title: string
  content: string
  type: 'choice' | 'multiple_choice' | 'true_false' | 'fill_blank' | 'short_answer' | 'programming'
  difficulty: 'easy' | 'medium' | 'hard'
  points: number
  options?: string[]
  correct_answer?: any
  explanation?: string
  tags?: string[]
  media_files?: MediaFile[]
  creator: User
  question_bank: number
  is_active: boolean
  created_at: string
  updated_at: string
}

export interface MediaFile {
  id: number
  file_name: string
  file_type: string
  file_size: number
  file_url: string
  created_at: string
}

// 考试相关类型
export interface Examination {
  id: number
  title: string
  description: string
  exam_type: string
  status: 'draft' | 'published' | 'ongoing' | 'finished'
  start_time: string
  end_time: string
  duration: number
  total_score: number
  pass_score: number
  question_count: number
  creator: User
  supervisors: User[]
  created_at: string
  updated_at: string
}

export interface ExaminationSession {
  id: number
  user: User
  examination: Examination
  status: 'not_started' | 'in_progress' | 'completed' | 'timeout' | 'submitted'
  started_at?: string
  finished_at?: string
  time_spent?: number
  total_score?: number
  passed?: boolean
  ip_address?: string
  user_agent?: string
  cheating_detected: boolean
  created_at: string
  updated_at: string
}

export interface ExaminationAnswer {
  id: number
  exam_session: ExaminationSession
  question: Question
  answer?: any
  text_answer?: string
  score?: number
  is_correct?: boolean
  time_spent?: number
  view_count: number
  status: string
  created_at: string
  updated_at: string
}

// 成绩相关类型
export interface GradeSheet {
  id: number
  title: string
  description: string
  examination?: Examination
  course?: number
  grading_standard: any
  status: 'draft' | 'calculating' | 'reviewed' | 'published' | 'archived'
  published_at?: string
  statistics?: any
  creator: User
  reviewer?: User
  reviewed_at?: string
  review_notes?: string
  grades_count: number
  created_at: string
  updated_at: string
}

export interface Grade {
  id: number
  grade_sheet: GradeSheet
  student: User
  exam_session: ExaminationSession
  raw_score?: number
  final_score?: number
  grade_level?: string
  is_passed: boolean
  rank?: number
  percentile?: number
  comments?: string
  adjustment_reason?: string
  adjusted_by?: User
  adjusted_at?: string
  created_at: string
  updated_at: string
}

export interface GradingStandard {
  id: number
  name: string
  description: string
  grade_levels: Record<string, any>
  passing_score: number
  full_score: number
  is_default: boolean
  scope: string
  creator: User
  is_active: boolean
  created_at: string
  updated_at: string
}

// 试卷相关类型
export interface ExamPaperTemplate {
  id: number
  name: string
  description: string
  template_type: 'standard' | 'adaptive' | 'random' | 'fixed'
  template_config: any
  default_duration: number
  default_total_score: number
  default_passing_score: number
  usage_count: number
  creator: User
  is_active: boolean
  is_public: boolean
  created_at: string
  updated_at: string
}

export interface ExamPaper {
  id: number
  title: string
  description: string
  template?: ExamPaperTemplate
  paper_type: 'formal' | 'practice' | 'mock' | 'diagnostic'
  status: 'draft' | 'generated' | 'reviewed' | 'published' | 'archived'
  generation_method: 'manual' | 'auto' | 'template' | 'ai'
  question_config: any
  duration: number
  total_score: number
  passing_score: number
  questions: any[]
  question_count: number
  average_difficulty?: number
  tags: string[]
  creator: User
  reviewer?: User
  reviewed_at?: string
  review_notes?: string
  usage_count: number
  is_public: boolean
  created_at: string
  updated_at: string
}

// 菜单项类型
export interface MenuItem {
  id: string
  title: string
  icon?: string
  path?: string
  children?: MenuItem[]
  hidden?: boolean
  badge?: string | number
  meta?: Record<string, any>
}

// 表格列配置类型
export interface TableColumn {
  prop: string
  label: string
  width?: number
  minWidth?: number
  sortable?: boolean
  filterable?: boolean
  formatter?: (row: any, column: any, cellValue: any) => string
  align?: 'left' | 'center' | 'right'
}

// 表单配置类型
export interface FormItem {
  prop: string
  label: string
  type: 'input' | 'textarea' | 'select' | 'radio' | 'checkbox' | 'date' | 'number' | 'upload'
  placeholder?: string
  options?: Array<{ label: string; value: any }>
  required?: boolean
  rules?: any[]
  span?: number
  disabled?: boolean
  hidden?: boolean
}

// 统计数据类型
export interface StatisticsData {
  total_users: number
  total_questions: number
  total_examinations: number
  total_grades: number
  active_users: number
  recent_activities: any[]
}

// 路由元信息类型
export interface RouteMeta {
  title?: string
  icon?: string
  requiresAuth?: boolean
  roles?: string[]
  keepAlive?: boolean
  hidden?: boolean
}

// 通用选项类型
export interface SelectOption {
  label: string
  value: any
  disabled?: boolean
}

// 文件上传类型
export interface UploadFile {
  name: string
  url: string
  size: number
  type: string
  status: 'uploading' | 'success' | 'error'
  percentage?: number
}

// 错误信息类型
export interface ErrorInfo {
  message: string
  code?: string
  details?: any
}

// 加载状态类型
export type LoadingState = {
  [key: string]: boolean
}

// 分页配置类型
export interface PaginationConfig {
  page: number
  pageSize: number
  total: number
  layout?: string
  pageSizes?: number[]
}

// 通知类型
export interface Notification {
  id: string
  title: string
  message: string
  type: 'success' | 'warning' | 'error' | 'info'
  duration?: number
  showClose?: boolean
  timestamp?: string
  created_at?: string
  is_read?: boolean
}